<?php

/**
 *  基础函数库
 * --------------------------------------------------------
 * @copyright  http://lin.97md.net
 * @access       MyDream
 * @author      zxing@97md.net
 * $Id: common.fun.php 68 2012-02-09 01:56:32Z thesmilelin@gmail.com $
 * $Date: 2012-02-09 01:56:32 +0000 (Thu, 09 Feb 2012) $
 * --------------------------------------------------------
 * @example
 */
// 获得 model 文件路径
function model($model) {
    return WEB_ROOT . '/include/' . $model . '.model.php';
}

// 用户密码保存加密算法
function password($password) {
    return md5($password);
}

// 得到访问用户的IP地址
function getIp() {
    $onlineip = 'Unknown';
    if (isset($_SERVER ['HTTP_X_FORWARDED_FOR'])) {
        $onlineip = $_SERVER ['HTTP_X_FORWARDED_FOR'];
        if (strstr($onlineip, ',')) {
            $onlineip = substr($onlineip, 0, strpos($onlineip, ','));
        }
    } elseif (isset($_SERVER ['HTTP_CLIENT_IP'])) {
        $onlineip = $_SERVER ['HTTP_CLIENT_IP'];
    } else {
        $onlineip = $_SERVER ['REMOTE_ADDR'];
        $c_agentip = 0;
    }
    $onlineip = preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $onlineip) ? $onlineip : 'Unknown';
    return $onlineip;
}

// 后台 弹出提示窗口 并跳转
function show_msg($message, $jump) {
    include WEB_ROOT . '/admin/template/message.html.php';
}

function confirm_msg($message1, $jump1, $jump2) {
    include WEB_ROOT . '/admin/template/message2.html.php';
}

function getTime() {
    echo Timer::spent();
}

function del($tablename1, $uid1) {
    $sql = 'DELETE FROM ' . $tablename1 . ' WHERE `id`=' . $uid1 . '';
    $result = mysql_query($sql);
}

//显示错误信息
function show_err() {
    if (mysql_errno()) {
        echo 'cuowu :' . mysql_error();
    }
}

//自动加载类
function __autoload($classname) {
    require WEB_ROOT . '/include/' . strtolower($classname) . '.class.php';
}


//function:编辑器
function fck_editor($content='') {
    include WEB_ROOT . '/admin/fckeditor/index.php';
    $fck = new FCKeditor('FCKeditor1');
    $fck->BasePath = '../admin/fckeditor/'; //fckeditor所在的位置
    $fck->Width = '100%';
    $fck->Height = "200";
    $fck->ToolbarSet = "Default";
    $fck->Value = $content;
    $fck_editor = $fck->CreateHtml();

    return $fck_editor;
}